package com.java.jvm.heap;

import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

//-Xmx128m -Xms128m -XX:+PrintGC
public class CacheTests {
    public static void main(String[] args) throws InterruptedException {
      List<WeakReference> cacheList=new ArrayList<>();
      Map<String,SoftReference> cacheMap=new HashMap<String,SoftReference>();
      int i=0;
      while(true){
          //cacheList.add(new WeakReference(new byte[1024*1024]));
          i++;
          cacheMap.put("key-"+i,new SoftReference(new byte[1024*1024]));
          TimeUnit.MILLISECONDS.sleep(500);
      }
    }
}
